package com.example.sxt_practise.net;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author gaofeng
 * @date 2022年06月09日 20:49
 */
public class NetApiTest {
    public static void main(String[] args) {
        try {
            InetAddress netAddress = InetAddress.getLocalHost() ;
            System.out.println(netAddress.getHostName());
            System.out.println(netAddress.getHostAddress());

            // 根据ip得到InetAddress对象 ： 根据ip进行DNS
            InetAddress address = InetAddress.getByName("www.163.com");
            String hostName = address.getHostName();
            System.out.println(address.getHostAddress());

        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
